home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
umich
/
music
/
patchlib.arc
/
PATCHSRC.ARC
/
PATCH.C
< prev
Wrap
Text File
|
1985-11-20
|
44KB
|
1,676 lines
#include <curses.h>
/*
* The following source code is being placed in the public domain
* with the sole restriction that if any of it is used in any manner,
* proper acknowledgement will be given to the original author -
* Eric Pettersen
*/
#define Effect (!((Random() >> 3) % weirdness))
#define sfunc(i,b) ((types[i][b] == 1) ? "high": ((types[i][b] == 2) ? \
" mid": " low"))
#define Get_roll(a) roll = get_roll(a)
#define AND_CHAR 241
#define OPTIONS 9
#define EDIT_OPTIONS 8
#define MAIN 0
#define EDIT 1
#define OK 0
#undef NULL
#define NULL -1
#define ABORT -2
#define BAD -3
#define VOICES 1000
/* either #define DX100 or CZ101 here */
#ifdef DX100
#define RANDOM_FILE "DX100.DTA"
#define VOICE_FILE "DXVOICES.DTA"
#define VOICE_SIZE 77
#define TOTAL_SIZE 93
#else
#define RANDOM_FILE "CZ101.DTA"
#define VOICE_FILE "CZVOICES.DTA"
#define VOICE_SIZE 81
#define TOTAL_SIZE 128
#define VDT 0
#define VRm 1
#define VRl 2
#define VD 3
#define SLOTS 4
char table[SLOTS][100]; /* the CZMIDI.DTA data file fits in this table */
int dca_kf[10] = { 0, 8, 17, 26, 36, 47, 58, 69, 82, 95 };
int dcw_kf[10] = { 0, 31, 44, 57, 70, 83, 96, 110, 146, 255 };
#endif
int weirdness;
int ranges[VOICE_SIZE]; /* data from DX/CZDATA.DTA */
int types[VOICE_SIZE][2]; /* is read into these */
int tries[VOICE_SIZE][2]; /* arrays */
char out[80], key_tbl[384]; /* data from KEYTAB.DTA goes in */
/* key_tbl array */
int cur_voice, load_ptr; /* cur_voice: points to where */
/* next saved voice will go in */
/* the voices array (and also, */
/* therefore, how many voices */
/* we have in the library) */
/* load_ptr: which voice from */
/* voices array was last loaded */
/* into the synth */
long cur_space; /* how much free space on disk */
unsigned char voices[VOICES][TOTAL_SIZE]; /* actual voices */
char v_names[VOICES+1][80]; /* associated voice names */
/* main: Handle all main menu I/O and call any subroutines requested */
main()
{
char key, ans;
char voice[TOTAL_SIZE], v_name[80], search_str[80];
int i, j, name_valid, load_voice, leng, found, init_rez;
if ((init_rez = Getrez()) == 0) Setscreen(-1L, -1L, 1);
init_curses();
scr_func(CLEAR_SCR);
printf("Getting old voices from file\n\r");
get_voices(v_names, voices);
load_ptr = -1;
printf("Getting random voice weights from file\n\r");
initialize();
show_screen(MAIN);
do {
pos_cursor(8, 3+OPTIONS);
scr_func(ERASE_TO_EOP);
switch((int)(key = Crawcin())) {
case 'n':
case 'N':
printf("n");
printf("\n\rmaking voice");
make_voice(voice);
load_ptr = cur_voice;
/* FALL THROUGH */
case 'r':
case 'R':
if (key == 'r' || key == 'R'){
printf("r");
}
if (load_ptr < 0)
printf("\n\rno current voice\n\r");
else {
printf("\n\rsending voice\n\r");
if (load_ptr == cur_voice)
send_voice(voice);
else
send_voice(voices[load_ptr]);
show_voice(load_ptr);
}
break;
case 's':
case 'S':
printf("s");
printf("\n\rreceiving voice\n\r");
#ifndef DEBUG
receive_voice(voice);
#endif
do {
do {
pos_cursor(0,5+OPTIONS);
scr_func(CLEAR_TO_EOL);
printf("enter voice name: \007");
printf("\n\r[ESC to abort]");
pos_cursor(18, 5+OPTIONS);
leng = get_str(v_name);
} while (leng == 0);
if (leng < 0) break;
name_valid = TRUE;
for(i=0; i<leng; i++)
if (v_name[i]<32 || v_name[i]>127) {
printf("\n\rName has invalid ");
printf("character in it - ");
printf("re-try");
name_valid = FALSE;
break;
}
v_name[i] = '\0';
if (name_valid)
for(i=0; i<cur_voice; i++) {
if(!strcmp(v_names[i],v_name))
{
printf("\n\rThere is al");
printf("ready a voice");
printf(" named '%s'",
v_name);
printf(" - re-try");
name_valid = FALSE;
break;
}
}
} while(name_valid == FALSE);
if (leng < 0) break;
#ifdef DX100
strncpy(voice+77, v_name, 10);
for(i=strlen(v_name); i<10; i++) voice[77+i] = ' ';
#endif
pos_cursor(0,6+OPTIONS);
scr_func(CLEAR_TO_EOL);
for(i=0; i<TOTAL_SIZE; i++) voices[cur_voice][i] = voice[i];
strcpy(v_names[cur_voice], v_name);
printf("writing voice '%s' to file\n\r", v_name);
write_voice(v_name, voice);
cur_voice++;
show_voice(load_ptr);
break;
case 'a':
case 'A':
printf("a");
goto test;
case 'l':
case 'L':
printf("l");
test:
if (cur_voice == 0) {
warn("No voices to load");
break;
}
if (key == 'a' || key == 'A') {
load_ptr = (load_ptr + 1) % cur_voice;
goto load_it;
}
load_voice = get_v_num(5+OPTIONS);
if (load_voice == ABORT) break;
load_ptr = load_voice;
load_it:
pos_cursor(0,6+OPTIONS);
scr_func(CLEAR_TO_EOL);
printf("Loading voice '%s'\n\r", v_names[load_ptr]);
send_voice(voices[load_ptr]);
show_voice(load_ptr);
break;
case 'w':
case 'W':
printf("w");
do {
pos_cursor(0, 5+OPTIONS);
scr_func(CLEAR_TO_EOL);
printf("New weirdness factor: ");
leng = get_num();
if (leng == BAD || leng == 0) {
printf("\n\rInput 1 or higher ");
printf("[ESC to abort]");
}
} while(leng == 0 || leng == BAD);
if (leng > 0) {
weirdness = leng;
show_weirdness();
}
break;
case 'e':
case 'E':
show_screen(EDIT);
edit();
show_screen(MAIN);
break;
case 'f':
case 'F':
printf("f");
Keytbl(key_tbl, key_tbl+128, key_tbl+256);
pos_cursor(0, 5+OPTIONS);
printf("Enter string(s) to search for: \n\r");
printf("[ESC to abort]");
pos_cursor(32, 5+OPTIONS);
leng = get_str(search_str);
Bioskeys();
if (leng <= 0) break;
found = -1;
pos_cursor(0, 8+OPTIONS);
printf(" # name\n\r");
printf("--- ----");
do {
found = search(search_str, found+1);
if (found < cur_voice) {
pos_cursor(0, 10+OPTIONS);
scr_func(CLEAR_TO_EOL);
printf("%03d '%s'", found,
v_names[found]);
pos_cursor(0, 6+OPTIONS);
scr_func(CLEAR_TO_EOL);
printf("Continue search (y/n)? \007");
printf("%c", (ans = Crawcin()));
}
else {
pos_cursor(0, 10+OPTIONS);
scr_func(CLEAR_TO_EOL);
printf("*** NONE");
pos_cursor(0, 6+OPTIONS);
scr_func(CLEAR_TO_EOL);
printf("-- Hit any key to continue --");
wait();
}
} while (found<cur_voice && (ans == 'y' || ans == 'Y'));
break;
case 'q':
case 'Q':
printf("q");
break;
default:
printf("\007");
printf("\n\rBad option '%c' - re-try", key);
break;
}
} while (key != 'q' && key != 'Q');
if (init_rez == 0) Setscreen(-1L, -1L, 0);
curses_cleanup();
}
/* get_voices: read the standard voice library file and initialize the
voices in memory */
get_voices(names, voice_data)
char names[][80], voice_data[][TOTAL_SIZE];
{
long result;
int handle;
check_disk();
if (cur_space < 80 + TOTAL_SIZE) {
warn(
"WARNING: There is not enough space on the disk to store more voices");
}
result = Fsfirst(VOICE_FILE, 0);
if (result == EFILNF) {
printf("file '%s' not found -- attempting to create\n\r",
VOICE_FILE);
handle = Fcreate(VOICE_FILE, 0);
if (handle < 0) {
sprintf(out, "cannot create '%s'", VOICE_FILE);
error(out);
}
else {
printf("'%s' created\n\r", VOICE_FILE);
Fclose(handle);
result = E_OK;
}
}
if (result == E_OK) {
handle = Fopen(VOICE_FILE, READ);
if (handle < 0) {
sprintf(out, "cannot open '%s'", VOICE_FILE);
error(out);
}
else {
printf("file opened\n\r");
}
}
else {
sprintf(out, "cannot find '%s'", VOICE_FILE);
error(out);
}
cur_voice = 0;
printf("reading in voice data\n\r");
while(TRUE) {
if (scan_name(handle, names[cur_voice]) != OK) break;
if (strlen(names[cur_voice]) > 0) {
if (scan_voice(handle, voice_data[cur_voice]) != OK)
break;